package com.zsd.android.arouter_api;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * 参数管理
 */
public class BundleManager {

    private Bundle bundle;
    //是否回调setResult()
    private boolean isResult;

    public BundleManager() {
        bundle = new Bundle();
    }

    //对外提供传参方法
    //@NonNull不允许传null, @Nullable允许传null
    public BundleManager withString(@NonNull String key, @Nullable String value) {
        bundle.putString(key, value);
        return this;
    }

    public BundleManager withResultString(@NonNull String key, @Nullable String value) {
        bundle.putString(key, value);
        isResult = true;
        return this;
    }

    public BundleManager withBoolean(@NonNull String key, @Nullable boolean value) {
        bundle.putBoolean(key, value);
        return this;
    }

    public BundleManager withInt(@NonNull String key, @Nullable int value) {
        bundle.putInt(key, value);
        return this;
    }

    public BundleManager withBundle(@NonNull String key, @Nullable Bundle value) {
        this.bundle = bundle;
        return this;
    }

    // 直接跳转startActivity
    public Object navigation(Context mContext) {
        return navigation(mContext, -1);
    }

    // forResult
    //这里的code，可能是resultCode，也可能是requestCode。取决于isResult
    public Object navigation(Context mContext, int code) {
        return RouterManager.getInstance().navigation(mContext, this, code);
    }

    public Bundle getBundle() {
        return bundle;
    }

    public boolean isResult() {
        return isResult;
    }
}
